<template>
    <div class="app-container">
        <div class="data-cards-container">
            <!-- 实时功率卡片 -->
            <div class="data-card power-card">
                <div class="card-header">
                    <div class="card-title">实时功率</div>
                    <div class="card-unit">kW</div>
                </div>
                <div class="card-content">
                    <div class="main-value">
                        {{ data.power.value }}
                        <span class="trend-indicator" :class="data.power.trend">
                            {{ data.power.trend === 'rise' ? '↑' : '↓' }}
                        </span>
                    </div>
                    <div class="card-details">
                        <div class="detail-item">
                            <span class="label">装机容量</span>
                            <span class="value">{{ data.power.capacity }} kWp</span>
                        </div>
                        <div class="time-info">
                            <span class="time-label">今日</span>
                            <span class="time-value">{{ data.power.todayHours }}h</span>
                        </div>
                    </div>
                </div>
            </div>
            <!-- 当日发电卡片 -->
            <div class="data-card daily-card">
                <div class="card-header">
                    <div class="card-title">当日发电量</div>
                </div>
                <div class="card-content">
                    <div class="main-value daily">
                        {{ data.daily.generation }}
                        <span class="value-unit">kW·h</span>
                    </div>
                    <div class="card-details">
                        <div class="detail-item">
                            <span class="label">当日收益</span>
                            <span class="value">{{ data.daily.income }}元</span>
                        </div>
                    </div>
                </div>
            </div>
            <!-- 本月发电卡片 -->
            <div class="data-card monthly-card">
                <div class="card-header">
                    <div class="card-title">本月发电量</div>
                </div>
                <div class="card-content">
                    <div class="main-value monthly">
                        {{ data.monthly.generation }}
                    </div>
                    <div class="card-details">
                        <div class="detail-item">
                            <span class="label">本月收益</span>
                            <span class="value">{{ data.monthly.income }}元</span>
                        </div>
                    </div>
                </div>
            </div>
            <!-- 本月发电卡片 -->
            <div class="data-card monthly-card">
                <div class="card-header">
                    <div class="card-title">本月发电量</div>
                </div>
                <div class="card-content">
                    <div class="main-value monthly">
                        {{ data.monthly.generation }}
                    </div>
                    <div class="card-details">
                        <div class="detail-item">
                            <span class="label">本月收益</span>
                            <span class="value">{{ data.monthly.income }}元</span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <el-row :gutter="20">
            <el-col :span="18">
                <div class="weather-power-card">
                    <!-- 交直流参数 -->
                    <div class="power-section">
                        <div class="power-solar">
                            <el-image :src="solarPanelUrl" class="power-image" />
                        </div>
                        <div class="power-line">
                            <div class="power-line-inner"></div>
                        </div>
                        <div>
                            <el-image :src="inverterUrl" class="power-image" />
                        </div>
                        <div class="power-line1">
                            <div class="power-line1-horizontal1">
                                <div class="power-line1-horizontal-inner1"></div>
                            </div>
                        </div>
                        <div class="power-wire">
                            <div>
                                <el-image :src="wireBracketUrl" class="power-image" />
                            </div>
                        </div>
                    </div>
                    <div class="parameters">
                        <div></div>
                        <div></div>
                    </div>
                </div>
                <div class="solar-panel-card">
                    <!-- 电量信息 -->
                    <div class="time_type">
                        <el-radio-group v-model="typeOfElectricity" @input="handleChangeTimeType">
                            <el-radio-button label="日"></el-radio-button>
                            <el-radio-button label="月"></el-radio-button>
                            <el-radio-button label="年"></el-radio-button>
                            <el-radio-button label="总"></el-radio-button>
                        </el-radio-group>

                        <div class="block">
                            <el-date-picker v-if="timeType" v-model="timeDate" :type="timeType" placeholder="选择日期">
                            </el-date-picker>
                        </div>
                    </div>

                    <div class="time_type" style="justify-content: center;color:#000">
                        <div class="block">
                            日发电量: 208.01 度
                        </div>
                        <div class="block">
                            日收益: 0 元
                        </div>
                        <div class="block">
                            日满发小时: 0.52 h
                        </div>
                    </div>
                    <el-row>
                        <el-col :span="24">
                            <PowerLevelEchart v-if="typeOfElectricity == '日'" />
                            <PowerLevelBarEchart v-if="typeOfElectricity !== '日'" :dates="dates" />
                        </el-col>
                    </el-row>
                </div>
                <div class="solar-panel-card">
                    <!-- 环保收益 -->
                    <div class="environmental_text">
                        环保收益
                    </div>
                    <div class="environmental">
                        <!-- <div class="environmental_content">
                            <el-image :src="treeUrl" class="environmental_image" />
                            <div class="environmental_img_text">
                                <div><span>78435.43</span> kg</div>
                                <div>累计节煤量</div>
                            </div>
                        </div> -->
                    </div>
                </div>
            </el-col>
            <el-col :span="6">
                <div class="solar-panel-card">
                    <!-- 光伏信息 -->
                    <el-image :src="inverterUrl" class="solar-panel-image" />
                    <div>SN码:<span>30100201A00236H00232</span></div>
                    <div>型号:<span>hopeSun 110KTL</span></div>
                    <div>额定功率:<span>110 kW</span></div>
                    <div>质保到期时间:<span>2028-12-09 </span></div>
                    <div>设备厂商:<span>---</span></div>
                </div>
                <div class="solar-panel-card">
                    <!-- 接入信息 -->
                    <div class="alarm_info_text">
                        <div class="alarm_title">接入信息</div>
                        <div class="weather-info">
                            <!-- 防逆流信息 -->
                            <div class="reverse-flow">
                                <span class="reverse-flow-text">更多 ></span>
                            </div>
                        </div>
                    </div>
                    <div>所属电站:<span>xxxx</span></div>
                    <div>接入容量:<span>110 kWp</span></div>
                    <div>电站地址:<span>湖北省孝感市孝南区孝感开发区孝天街道激光产业园 </span></div>
                    <div class="alarm_info">
                        <div class="equipment_info_detail">
                            <el-image :src="inverterUrl" class="equipment-image" />
                            <div style="display: flex;flex-direction: column;">
                                <span>电网异常</span>
                                <span style="color: #666666;">2025-10-14 06:16:31</span>
                            </div>
                        </div>
                    </div>
                </div>
            </el-col>
        </el-row>
    </div>
</template>

<script>
import PowerGenerateEchart from './powerGenerateEchart.vue';
import PowerLevelEchart from './powerLevelEchart.vue';
import PowerLevelBarEchart from './powerLevelBarEchart.vue';
import Information from './information.vue';
import Equipment from './equipment.vue';
import AlarmInfo from './alarmInfo.vue';
export default {
    name: 'EquipmentTree',
    components: { PowerGenerateEchart, PowerLevelEchart, PowerLevelBarEchart, Information, Equipment, AlarmInfo },
    data() {
        return {
            data: {
                power: {
                    value: '35.43',
                    trend: 'fall',
                    capacity: '400',
                    todayHours: '3.52'
                },
                daily: {
                    generation: '1370.84',
                    income: '0'
                },
                monthly: {
                    generation: '9929.74',
                    income: '0'
                },
                total: {
                    generation: '36245.03',
                    income: '0'
                }
            },
            solarPanelUrl: require('@/assets/images/solar_panel.png'),
            inverterUrl: require('@/assets/images/inverter.png'),
            wireBracketUrl: require('@/assets/images/wire_bracket.png'),
            solarPanelImageUrl: require('@/assets/images/plantImg-default.jpeg'),
            // 电量数据统计时间类型
            typeOfElectricity: '日',
            timeDate: '2025-10-11',
            timeType: 'date',
            dates: null,
            stationId: 'stationId'
        }
    },
    mounted() {
        // 模拟实时数据更新
        this.updateData()
    },
    beforeDestroy() {
        if (this.updateTimer) {
            clearInterval(this.updateTimer)
        }
    },
    methods: {
        toggleNode(nodeId) {
            this.expandedNodes[nodeId] = !this.expandedNodes[nodeId]
        },

        // 更新数据的方法，可以从父组件调用
        updateData(newData) {
            this.data = { ...this.data, ...newData }
        },

        // 时间选择绑定值变化时触发的事件
        handleChangeTimeType(timetype) {
            console.log(timetype);
            switch (timetype) {
                case '日':
                    this.timeType = 'date';
                    this.dates = this.getToday24HoursDisplay();
                    break;
                case '月':
                    this.timeType = 'month';
                    this.dates = this.getCurrentMonthDaysArray();
                    break;
                case '年':
                    this.timeType = 'year';
                    this.dates = this.getCurrentYearMonthsArray();
                    break;
                case '总':
                    this.timeType = null;
                    const currentYear = new Date().getFullYear();
                    this.dates = this.getYearsRange(currentYear - 7, currentYear);
                    break;

                default:
                    break;
            }
            console.log(this.dates);

        }
    }
}
</script>

<style scoped lang="scss">
.data-cards-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    /* padding: 20px; */
}

.data-card {
    background: white;
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    transition: all 0.3s ease;
    border-left: 4px solid transparent;
    position: relative;
    overflow: hidden;
}

.data-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.data-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, transparent 0%, rgba(255, 255, 255, 0.6) 50%, transparent 100%);
}

/* 卡片颜色主题 */
.power-card {
    border-left-color: #409eff;
    background: linear-gradient(135deg, #f0f7ff 0%, #ffffff 100%);
}

.power-card::before {
    background: linear-gradient(90deg, transparent 0%, #409eff 50%, transparent 100%);
}

.daily-card {
    border-left-color: #67c23a;
    background: linear-gradient(135deg, #f0f9eb 0%, #ffffff 100%);
}

.daily-card::before {
    background: linear-gradient(90deg, transparent 0%, #67c23a 50%, transparent 100%);
}

.monthly-card {
    border-left-color: #e6a23c;
    background: linear-gradient(135deg, #fdf6ec 0%, #ffffff 100%);
}

.monthly-card::before {
    background: linear-gradient(90deg, transparent 0%, #e6a23c 50%, transparent 100%);
}

.total-card {
    border-left-color: #f56c6c;
    background: linear-gradient(135deg, #fef0f0 0%, #ffffff 100%);
}

.total-card::before {
    background: linear-gradient(90deg, transparent 0%, #f56c6c 50%, transparent 100%);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.card-title {
    font-size: 16px;
    font-weight: 600;
    color: #303133;
    position: relative;
}

.card-title::after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 0;
    width: 20px;
    height: 2px;
    background: currentColor;
    opacity: 0.6;
}

.card-unit {
    font-size: 12px;
    color: #909399;
    background: rgba(144, 147, 153, 0.1);
    padding: 2px 6px;
    border-radius: 10px;
}

.card-content {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.main-value {
    font-size: 36px;
    font-weight: bold;
    line-height: 1;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* 数值颜色 */
.power-card .main-value {
    color: #409eff;
}

.daily-card .main-value {
    color: #67c23a;
}

.monthly-card .main-value {
    color: #e6a23c;
}

.total-card .main-value {
    color: #f56c6c;
}

.trend-indicator {
    font-size: 20px;
    font-weight: normal;
}

.trend-indicator.rise {
    color: #67c23a;
}

.trend-indicator.fall {
    color: #f56c6c;
}

.value-unit {
    font-size: 16px;
    color: #909399;
    font-weight: normal;
}

.card-details {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 12px;
    border-top: 1px solid #f0f0f0;
}

.detail-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.detail-item .label {
    font-size: 12px;
    color: #909399;
}

.detail-item .value {
    font-size: 14px;
    font-weight: 500;
    color: #303133;
}

.time-info {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(64, 158, 255, 0.1);
    padding: 6px 12px;
    border-radius: 16px;
    border: 1px solid rgba(64, 158, 255, 0.2);
}

.time-label {
    font-size: 12px;
    color: #409eff;
}

.time-value {
    font-size: 14px;
    font-weight: 600;
    color: #409eff;
}

/* 响应式设计 */
@media (max-width: 1200px) {
    .data-cards-container {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .data-cards-container {
        grid-template-columns: 1fr;
        gap: 16px;
        padding: 16px;
    }

    .data-card {
        padding: 20px;
    }

    .main-value {
        font-size: 28px;
    }

    .card-header {
        margin-bottom: 16px;
    }
}

/* 加载状态 */
.data-card.loading .main-value,
.data-card.loading .detail-item .value {
    color: transparent;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
    border-radius: 4px;
}

@keyframes loading {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

.weather-power-card {
    width: 100%;
    background: #ffffff;
    border: 1px solid #e8e8e8;
    border-radius: 12px;
    padding: 20px;
    margin-top: 20px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    line-height: 1.4;
}

.weather-info {
    font-size: 14px;
    color: #606266;
}

/* 电力部分样式 */
.power-section {
    display: flex;
    flex-direction: row;
    justify-content: space-around;
    align-items: center;
    gap: 12px;
    position: relative;
}



.power-solar {
    position: relative;
}

.power-line {
    position: absolute;
    top: calc(50% - 2px);
    right: none;
    bottom: none;
    left: 180px;
    width: calc(36% - 100px);
    height: 2px;
    background: #00b974;

    .power-line-inner {
        position: absolute;
        animation: pvToDevice 4s linear infinite forwards;
    }

    .power-line-inner::before {
        content: "▼";
        color: #00b974;
    }
}

@keyframes pvToDevice {
    from {
        transform: rotate(-90deg);
        top: -10px;
        left: 0;
    }

    to {
        transform: rotate(-90deg);
        top: -10px;
        left: 220px;
    }
}

@keyframes pvToHorizontal {
    0% {
        transform: rotate(-90deg);
        top: -10px;
        left: 0;
    }

    100% {
        transform: rotate(-90deg);
        top: -10px;
        left: 145px;
    }
}

@keyframes pvToHorizontal1 {
    0% {
        transform: rotate(-90deg);
        top: -10px;
        left: 0;
    }

    100% {
        transform: rotate(-90deg);
        top: -10px;
        left: 270px;
    }
}

@keyframes pvToOrdinate1 {
    0% {
        transform: rotate(0deg);
        top: -10px;
        left: -8px;
    }

    50% {
        transform: rotate(0deg);
        top: 60px;
        left: -8px;
    }

    100% {
        transform: rotate(-90deg);
        top: 60px;
        left: 60px;
    }
}

.power-line1 {
    position: absolute;
    top: calc(50% - 2px);
    right: none;
    bottom: none;
    left: calc(56% - 6px);



    .power-line1-horizontal1 {
        position: absolute;
        left: 0;
        width: 270px;
        height: 2px;
        background: #00b974;
    }

    .power-line1-horizontal-inner1 {
        position: absolute;
        animation: pvToHorizontal1 3s linear infinite forwards;
    }

    .power-line1-horizontal-inner1::before {
        content: "▼";
        color: #00b974;
    }
}

.power-wire {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
}

.power-image {
    width: 135px;
    height: 135px;
    z-index: 2;
}

// 光伏板信息
.solar-panel-card {
    width: 100%;
    background: #ffffff;
    border: 1px solid #e8e8e8;
    border-radius: 12px;
    padding: 20px;
    margin-top: 20px;
    // font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    line-height: 1.4;
    display: flex;
    flex-direction: column;
    font-size: 14px;
    justify-content: center;
    color: #666666;

    div {
        padding: 5px 0;
    }

    span {
        color: #000;
    }

    .solar-panel-image {
        width: 150px;
        height: 150px;
    }
}

// 电量数据统计信息
.time_type {
    display: flex;
    align-items: center;
    gap: 20px;
}

.power_generate {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 200px;
}

.time-line-info {
    display: flex;
    justify-content: center;
    align-items: center;
}

.time-line {
    width: 5px;
    height: 200px;
    background: #909399;
    border-radius: 50%;
}

.reverse-flow {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    color: #606266;
}

.reverse-flow-text {
    color: #909399;
}

.reverse-flow-value {
    color: #409eff;
    font-weight: 500;
}

.power-display {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: #f5f7fa;
    border-radius: 6px;
    border: 1px solid #e4e7ed;
}

.power-zero {
    font-size: 13px;
    color: #c0c4cc;
}

.power-current {
    font-size: 14px;
    font-weight: 600;
    color: #e6a23c;
}

// 环保收益
.environmental {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.environmental_image {
    width: 50px;
    height: 50px;
    object-fit: contain;
}

.environmental_content {
    display: flex;
    align-items: center;
    height: 80px;


    span {
        font-size: 18px;
        font-weight: 600;
    }
}

.environmental_text {
    font-style: 18px;
    color: #000;
    font-weight: 700;
}

.environmental_img_text {
    display: flex;
    flex-direction: column;
    margin-left: 20px;
}

// 报警信息
.alarm_info_text {
    display: flex;
    justify-content: space-between;

    .alarm_title {
        font-size: 20px;
        color: #000;
        font-weight: 700;
    }
}

.equipment_info_detail {
    display: flex;
    align-items: center;
    justify-content: space-around;
    margin: 5px 0;
    background: #f5f5f5;
    padding: 10px 20px !important;
}

.equipment-image {
    width: 80px;
    height: 80px;
}

.alarm_tags {
    display: flex;
    align-items: center;

    .el-tag {
        border-radius: 20px;
        color: #1890ff !important;
    }
}

.alarm_tags_text {
    margin-left: 20px;
    font-size: 14px;
    font-weight: 700;
}
</style>